<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2014 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Forpastime <forpastime@qq.com>
// +----------------------------------------------------------------------
namespace plugins\rabbitmq\controller; 

use cmf\controller\PluginAdminBaseController;

class AdminIndexController extends PluginAdminBaseController
{

    public function _initialize()
    {
        $adminId = cmf_get_current_admin_id();//获取后台管理员id，可判断是否登录
        if (!empty($adminId)) {
            $this->assign("admin_id", $adminId);
        } else {
            $this->error('未登录');
        }
    }

    public function index()
    {
        $consumerDir =  PLUGINS_PATH.'/rabbitmq/consumer/';
        $a = scandir($consumerDir);

        $list = array();
        foreach($a as $k => $v){
            if(strpos($v,'.php')){
                $file['name']=explode(".",$v)[0];
                $file['path']= $consumerDir;
                array_push($list,$file);
            }
        }

        $this->assign('list',$list);
        return $this->fetch();
    }

    public function edit()
    {
        $filename =  PLUGINS_PATH.'rabbitmq/consumer/'.$this->request->param("name").'.php';
        $hadle = fopen($filename,"r");
        // $contents = fread($hadle,filesize(($filename)));
        while(!feof($hadle)){
            $buffer = fgets($hadle,4096);
            $a = trim($buffer);
            echo $a;
        }
        // $this->assign('contents',$contents);
        fclose($hadle);
        // return $this->fetch();
    }
}